a = int(input('Введите четырехзначное число: '))
maxx = 0
dell = 2
b = a // 1000
c = a // 100
d = a // 100 % 10
e = a // 10 % 100
f = a // 10 % 100 % 10
g = a % 1000 % 100
h = a % 1000 % 100 % 10
j = a // 10
k = a % 1000
mas = [a, b, c, d, e, f, g, h, j, k]
for i in mas:
    m = i
    #print(i)
    it = True
    dell = 2
    if i == 1:
        it = False
    while it and dell <= i - 1:
        if i % dell == 0:
            it = False
        dell += 1
    if it:
        if m > maxx:
                maxx = m
print(maxx)
#print(b, c, d, e, f, g, h, j, k)